package com.helwen.entity;

import com.baomidou.mybatisplus.annotation.*;
import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.io.Serializable;
import java.math.BigDecimal;
import java.time.LocalDateTime;

/**
 * <p>
 * 送货单详情
 * </p>
 *
 * @author heqiwen
 * @since 2020-12-04
 */
@Data
@EqualsAndHashCode(callSuper = false)
@TableName(value = "city_delivery_details", autoResultMap = true)
public class DeliveryDetails implements Serializable {

    private static final long serialVersionUID = 1L;

    /**
     * 主键
     */
    @TableId(type = IdType.ASSIGN_ID)
    private Long deliveryDetailId;

    /**
     * 送货单id
     */
    private Long deliveryId;
    /**
     * 二级仓id
     */
    private Long warehouseId;
    /**
     * 送货单状态 0 新建 1 待收货 2 已完成 3 拒收
     */
    private Integer state;
    /**
     * 商品id
     * */
    @TableField(insertStrategy = FieldStrategy.NEVER,updateStrategy = FieldStrategy.NEVER)
    private Long goodsId;


    /*<!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.macro.mall.entity.Demand">
        <id column="demand_id" property="demandId" />
        <result column="city" property="city" />
        <result column="warehouse_id" property="warehouseId" />
        <result column="warehouse_name" property="warehouseName" />
        <result column="goods_id" property="goodsId" />
        <result column="goods_menu_id" property="goodsMenuId" />
        <result column="goods_info" property="goodsInfo" typeHandler="com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler" />
        <result column="goods_number" property="goodsNumber" />
        <result column="state" property="state" />
        <result column="create_user" property="createUser" />
        <result column="create_time" property="createTime" />
        <result column="over_time" property="overTime" />
        <result column="is_delete" property="isDelete" />
    </resultMap>*/
    /**
     * 商品详情   字段保存的是一个json数据的处理
     */
    @TableField(typeHandler = JacksonTypeHandler.class)
    private GoodsInfoDto goodsInfo;
    /**
     * 商品件数
     */
    private Integer goodsNumber;
    /**
     * 成本价格(每斤)
     */
    private BigDecimal costPrice;
    /**
     * 确认收货件数
     */
    private LocalDateTime receivedTime;
    /**
     * 确认收货件数
     */
    private Integer receivedNumber;
    /**
     * 备注
     */
    private String remarks;
    /**
     * 确认收货图片
     */
    private String image;
    /**
     * 创建时间  与MyMetaObjectHandler 类配合
     */
    @TableField(fill = FieldFill.INSERT)
    private LocalDateTime createTime;
    /**
     * 城市   与MyMetaObjectHandler 类配合
     */
    @TableField(fill = FieldFill.INSERT)
    private String city;
    /**
     * 大车任务id
     * */
    private Long taskDcId;
    /**
     * 大车任务是否结束
     * */
    private Integer taskDcEnd;
    /**
     * 发货单id
     * */
    private Long invoiceId;

    private Integer isDelete;


    /**
     * 商品上架id
     */
    @TableField(insertStrategy = FieldStrategy.NEVER,updateStrategy = FieldStrategy.NEVER)
    private Long goodsMenuId;

    /**
     * 商品名称
     */
    @TableField(insertStrategy = FieldStrategy.NEVER,updateStrategy = FieldStrategy.NEVER)
    private String goodsName;


    public static DeliveryDetails of(String city, Long deliveryId, Long warehouseId, GoodsInfoDto goodsInfo, Integer goodsNumber) {
        DeliveryDetails deliveryDetails = new DeliveryDetails();
        deliveryDetails.setDeliveryId(deliveryId);
        deliveryDetails.setWarehouseId(warehouseId);
        deliveryDetails.setGoodsInfo(goodsInfo);
        deliveryDetails.setGoodsNumber(goodsNumber);
        deliveryDetails.setCity(city);
        deliveryDetails.setCostPrice(goodsInfo.getWarehousePurchasePrice());
        return deliveryDetails;
    }

}
